<template>
  <div>
    <el-row>
      <el-col v-for="app in appList" :key="app.id" :span="6" class="box-card">
        <el-card class="appCard" shadow="hover">
          <div slot="header" class="card-header clearfix">
            <span>{{ app.appName }}</span>
            <el-button style="float: right; padding: 3px 0" type="text"
                       @click="$refs.appSettingDialog.open(app.appName)"
            >设置
            </el-button>
          </div>
          <div class="card-body">
            <h1 class="appShowName">{{ app.appShowName }}</h1>
            <div class="card-button">
              <el-button v-for="b in filterBtn(app)" :key="b.name" :type="b.style" size="mini"
                         @click="goPage({btnType:b.type,appName:app.appName})">{{ b.name }}
              </el-button>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <AppSettingDialog ref="appSettingDialog"/>
  </div>
</template>
<script>
import {appListApi} from "@/api/manage";
import AppSettingDialog from "../../manage/appList/components/AppSettingDialog";

export default {
  name: "deploy",
  data() {
    return {
      appList: {},
      appSetting: {},
      appSettingVisible: false,
      btns: [
        {type: "logsearch", name: "日志", style: "warning"},
        {type: "build", name: "构建", style: "success"},
        {type: "deploy", name: "部署", style: "primary"},
      ],
    };
  },
  components: {
    AppSettingDialog,
  },
  methods: {
    goPage(param) {
      this.$router.push({
        name: param.btnType,
        query: {appName: param.appName},
      });
    },
    openSetting(appInfo) {
      this.appSetting = appInfo;
      this.appSettingVisible = true;
    },
    async reloadAppList() {
      const res = await appListApi();
      if (res) {
        this.appList = res;
      }
    },
    filterBtn(app) {
      return this.btns.filter((b) => {
        if (b.type == "build" && app.buildType == null) {
          return false;
        }
        if (b.type == "deploy" && app.deployType == null) {
          return false;
        }
        return true;
      });
    },
  },
  created() {
    this.reloadAppList();
  },
};
</script>
<style scoped>
.appCard {
  margin: 20px 20px 10px 20px;
  height: 230px;
  background: #fdfdfd;
  color: #606266;
  text-align: center;
}

.appCard .appShowName {
  height: 80px;
  line-height: 80px;
  font-size: 30px;
}

.appCard /deep/ .el-card__header {
  background: #f2f6fc;
  font-size: 20px;
  color: #409eff;
  text-align: left;
}

.el-dropdown {
  margin-right: 10px;
}
</style>